$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'../..','ext_pr1/lib')
require 'ext_pr1_v4'
require 'Aufgabe_2'

# Konstante Funktionen
def square(v) v*v end

# Funktion zum ermitteln der Summe der Quadrate der beiden größten Werte aus 3
# larger_sum_square :: (val1, val2, val3)
#   INT x INT x INT =>? NAT
#
# Tests
#   larger_sum_square(1,2,3) = > 13
#   larger_sum_square(2,3,1) = > 13
#   larger_sum_square(3,2,1) = > 13
#   larger_sum_square(2,1,3) = > 13
#   larger_sum_square(3,1,2) = > 13
#   larger_sum_square(1,3,2) = > 13
#   larger_sum_square(2,2,2) = > 8
#   larger_sum_square(2,2,3) = > 13
#   larger_sum_square(2,3,2) = > 13
#   larger_sum_square(3,2,2) = > 13
#   larger_sum_square(2,2,3) = > 13
#   
#   larger_sum_square("a",3,2) = > ERR
#   larger_sum_square(1,"a",2) = > ERR
#   larger_sum_square(1,3,"a") = > ERR
#   larger_sum_square(true,3,2) = > ERR
#   larger_sum_square(1,true,2) = > ERR
#   larger_sum_square(1,3,true) = > ERR
#   larger_sum_square(1.0,3,2) = > ERR
#   larger_sum_square(1,3.0,2) = > ERR
#   larger_sum_square(1,3,2.0) = > ERR
#   larger_sum_square() = > ERR
#   larger_sum_square(1) = > ERR
#   larger_sum_square(1,2) = > ERR

def larger_sum_square(val1, val2, val3)
   check_pre((val1.int? and val2.int? and val3.int?))
   #values = (val1 < val2) ? pair_of_biggest_int(val2,val1,val3) : pair_of_biggest_int(val1,val2,val3)
   values = pair_of_biggest_int(val1,val2,val3)
   square(values[0])+square(values[1])
end

def pair_of_biggest_int(a,b,c)
   #[max_int(c,b),a]
   if    (a <= c and a <= b) then [b,c]
   elsif (b <= a and b <= c) then [a,c]
   else                           [a,b]
   end
   
   # oder in Kondionalform -> ist aber nicht lesbarer
   # (a <= c and a <= b) ? [b,c] : (b <= a and b <= c) ? [a,c] : [a,b]
end












# Notiz
# Funktion um die Maximalwerte zurückzugeben
# pair_of_biggest_int :: (a,b,c)
#   INT x INT x INT => [INT,INT] :: (a >= b ? true : a >= c)
#
# Tests
#   pair_of_biggest_int(2,1,3) = > [3,2]
#   pair_of_biggest_int(2,2,3) = > [3,2]
#   pair_of_biggest_int(2,2,2) = > [2,2]
#   pair_of_biggest_int(2,1,2) = > [2,2]
#   pair_of_biggest_int(1,2,3) = > ERR
#
#   pair_of_biggest_int("a",3,2) = > ERR
#   pair_of_biggest_int(1,"a",2) = > ERR
#   pair_of_biggest_int(1,3,"a") = > ERR
#   pair_of_biggest_int(true,3,2) = > ERR
#   pair_of_biggest_int(1,true,2) = > ERR
#   pair_of_biggest_int(1,3,true) = > ERR
#   pair_of_biggest_int(1.0,3,2) = > ERR
#   pair_of_biggest_int(1,3.0,2) = > ERR
#   pair_of_biggest_int(1,3,2.0) = > ERR
#   pair_of_biggest_int() = > ERR
#   pair_of_biggest_int(1) = > ERR
#   pair_of_biggest_int(1,3) = > ERR

